#include <QThread>
#include "FunctionTransfer.h"

//在全局数据区实例化一个FunctionTransfer的实例，该实例所在的县城就是主线程。


FunctionTransfer main_thread_forward;
void FunctionTransfer::execinmain(std::function<void()> f)
{
    main_thread_forward.exec(f);
}

FunctionTransfer::FunctionTransfer(QObject *parent) :
    QObject(parent)
{
    connect(this,SIGNAL(comming(std::function<void()>)),this,SLOT(exec(std::function<void()>)),Qt::BlockingQueuedConnection);
}


void FunctionTransfer::exec(std::function<void()> f)
{
//    if(QThread::currentThread() == qApp->thread())
//    {
//        f();
//    }
//    else
//    {
//        emit this->comming(f);
//    }
    emit this->comming(f);
}
